﻿@{
    ViewBag.Title = L("Ribbon_UserManagement");
}

<div class="lineinput">
    <div id="grid"></div>
</div>
<script type="text/x-kendo-template" id="template">
    <div style="text-align:right;">
        @Html.EnumDropdownList("RoleLevel", Self.RoleLevel, RoleLevel.Anonymous, Self.RoleLevel, new { style="float:left; text-align:left;" })
        <button type="button" onclick="goto('@Url.Action("EditUser")');" class="k-button k-button-icontext"><span class="k-icon k-add"></span>@LRaw("Ribbon_CreateUser")</button>
        <button type="button" onclick="ajaxDel($('input[name=UserID]').checkedVal())" class="k-button k-button-icontext"><span class="k-icon k-delete"></span>@LRaw("Ribbon_DeleteUser")</button>
    </div>
</script>
<script type="text/javascript">
    var role = '';
    $(document).ready(function () {
        $('#grid').grid({transport:{
                read: {
                    url: '@Url.Action("QueryUsers")',
                    dataType: "json",
                    type: "POST",
                    data:{
                        role:function(){
                            return role;
                        }
                    }
                }
            },
            pageSize: @ViewBag.PageSize,
            columns:[
                { title: 'chkall', template: '<input type="checkbox" value="#= UserID #" name="UserID"/>', width: "28px" },
                { field: 'UserName', title: '@LRaw("User_UserName")', template: '#= DisplayName #（#= UserName #）\
                <div class="actionpanel">\
                    <a onclick="goto(\'@Url.Action("EditUser")?userid=#= UserID #\');" title="@LRaw("Edit")" href="javascript:void(0);"><span style="width:20px;" class="k-icon k-edit"></span> @LRaw("Edit") </a> \
                    <a onclick="ajaxDel(#= UserID #);" title="@LRaw("Delete")" href="javascript:void(0);"><span class="k-icon k-delete"></span> @LRaw("Delete") </a>\
                </div>' },
                { field: 'RoleLevel', title: '@LRaw("User_RoleLevel")' },
                { field: "AccountStatus", title: '@LRaw("User_AccountStatus")' },
                { field: "CreateDate", title: '@LRaw("User_CreateDate")'}
            ],
            toolbar: '#template',
            checkall: 'UserID'}).find('#RoleLevel').kendoDropDownList({change:function(){
                role = this.value();
                grid.refresh();
            }});
    });

    function ajaxDel(ids){
        if(!ids) {
            showError('@LRaw("Action_SelectedFirst", L("Action_User"))');
            return;
        }
        ajaxDelete('@Url.Action("DeleteUsers")',
        {
            ids:function(){
                return ids;
            }
        }, 
        function(data){
            grid.refresh();
        }, 
        '@LRaw("Action_DeletedConfirm", L("Action_User"))');
    }
</script>